{% extends 'TopxiaWebBundle:CourseManage:layout.html.twig' %}

{% block title %}{{'价格设置'|trans}} - {{ parent() }}{% endblock %}

{% set side_nav = 'price' %}
{% set script_controller = 'course-manage/price' %}
{% block main %}

<div class="panel panel-default panel-col">
  <div class="panel-heading">{{'价格设置'|trans}}</div>
  <div class="panel-body">
    {{ web_macro.flash_messages() }}

    {% set currency = (setting('coin.coin_enabled') and setting('coin.price_type') == 'Coin') ? 'coin' : 'default' %}
    {% set coinRate = setting('coin.cash_rate', 1) %}

    {% if canModifyPrice %}
      <form class="form-horizontal" id="price-form" method="post" action="{{path('course_manage_price',{id:course.id})}}" data-cashrate="{{setting('coin.cash_rate', 1)}}">
        <div class="form-group">
          <label class="col-md-2 control-label">{{ '课程购买'|trans }}</label>
          <div class="col-md-8 controls radios">
            {{ radios('buyable', {'1':'开启'|trans, '0':'关闭'|trans}, course.buyable|default(1) ) }}
            <div class="help-block">{{ '关闭后课程将无法在线购买加入、由教师/管理员后台导入。'|trans }}</div>
          </div>
        </div>
        {% if currency == 'coin' %}
          <div class="form-group">
            <label class="col-md-2 control-label">{{'%coin_name%价格'|trans({'%coin_name%':setting('coin.coin_name')})}}</label>
            <div class="col-md-8 controls">
              <input type="text" name="price" class="form-control course-current-price" value="{{course.price}}">
              {% if discount %}
                <div class="alert alert-warning">
                  <small>{{'当前课程正处于「 %name% 」打折活动中。'|trans({'%name%': discount.name})}}
                  {{'折扣'|trans}}： <strong>{{'%discount%折'|trans({'%discount%': course.discount}) }} </strong>，
                  {{'折后价'|trans}}：<strong> <span class="course-discount-price" data-discount="{{ course.discount }}">{{ course.coinPrice }}</span> {{setting('coin.coin_name')}}</strong>。</small>
                </div>
              {% endif %}
            </div>
          </div>
        {% else %}
          <div class="form-group">
            <label class="col-md-2 control-label">{{'价格'|trans}}</label>
            <div class="col-md-8 controls">
              <input type="text" name="price" class="form-control course-current-price" value="{{course.originPrice}}">
              <div class="help-block">
              </div>
              {% if discount %}
                <div class="alert alert-warning">
                  {{'当前课程正处于「 %name% 」打折活动中。'|trans({'%name%':discount.name})}}<br>
                  {{'折扣'|trans}}： <strong>{{'%discount%折'|trans({'%discount%': course.discount}) }} </strong>，
                  {{'折后价'|trans}}：<strong><span class="course-discount-price" data-discount="{{ course.discount }}">{{ course.price }}</span> {{'元'|trans}}</strong>。
                </div>
              {% endif %}
              {% if course.type == 'normal' %}
                <div>
                   <a href="{{path('content_course_rule')}}" target="_blank">【查看课程细则】</a>
                </div>
              {% endif %}

            </div>
          </div>
        {% endif %}

        <div class="form-group">
          <label class="col-md-2 control-label">{{ '购买截止日期'|trans }}</label>
          <div class="col-md-8 controls radios">
            {{ radios('enableBuyExpiryTime', {1:'是'|trans, 0:'否'|trans}, course.buyExpiryTime|default(0) > 0) }}
          </div>
        </div>

        <div class="form-group {% if not course.buyExpiryTime %}hide{% endif %}" id="buyExpiryTime">
          <div class="col-md-8 controls col-md-offset-2">
            <input type="text" class="form-control width-input width-input-large" name="buyExpiryTime" {% if course.buyExpiryTime %} value="{{ course.buyExpiryTime|date('Y-m-d') }}" {% endif %}>
          </div>
        </div>

        {% if is_plugin_installed('Vip') and setting('vip.enabled') %}
          <div class="form-group">
            <label class="col-md-2 control-label">{{'会员课程设置'|trans}}</label>
            <div class="col-md-8 controls">
              <select name="vipLevelId" class="form-control width-input width-input-large">
                {{ select_options(levels, course.vipLevelId, '无'|trans) }}
              </select>
              <div class="help-block">{{'设置会员课程后，该会员及更高等级会员，可免费学习。'|trans}}</div>
            </div>
          </div>
        {% endif %}

        {% if setting('storage.upload_mode') == 'cloud' and course.type == 'normal' %}
        <div class="form-group">
            <label class="col-md-2 control-label">{{'开启视频试看'|trans}}</label>
            <div class="col-md-8 controls radios">
              {{ radios('tryLookable', {1:'是'|trans, 0:'否'|trans}, course.tryLookable|default(0)) }}
              <div class="help-block">{{'开启后，此课程的所有'|trans}}<a href="http://open.edusoho.com/show/cloud/video">云视频</a>{{'课时都支持试看。'|trans}}</div>
            </div>
        </div>

        <div class="form-group {% if course.tryLookable|default(0) !=1 %}hide{% endif %}" id = "tryLookTimeGroup">
            <label class="col-md-2 control-label">{{'试看时长'|trans}}</label>
            <div class="col-md-8 controls">
               <select name="tryLookTime" class='form-control width-input width-input-large'>
                {% for minute in 1..10 %}
                  <option value="{{ minute }}" {% if minute == course.tryLookTime %}selected{% endif %}>{{minute}}{{'分钟'|trans}}</option>
                {% endfor %}
               </select>
              <div class="help-block"></div>
            </div>
        </div>
        {% endif %}

        <div class="form-group">
          <div class="col-md-offset-2 col-md-8 controls">
            <button class="btn btn-fat btn-primary" id="price-save-btn" type="submit">{{'保存'|trans}}</button>
            <input type="hidden" name="_csrf_token" value="{{ csrf_token('site') }}">
          </div>
        </div>

      </form>
    {% else %}
      <div class="alert alert-danger">{{'抱歉，您无权设置课程价格，如有需要请联系网站管理员！'|trans}}</div>
    {% endif %}
  </div>
</div>
{% endblock %}